/*
{
"状态":1,
"名称":"新增-cmd权限资料",
"作者":"陈泽椿",
"创建时间":"2018-10-29",
"功能":"新增-cmd权限资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @cmd_id varchar(100) ,@cmd_name varchar(100) , @classify varchar(100) , @remarks varchar(100)
DECLARE @cmd_tree_key INT
DECLARE @cmd_power_id varchar(100) 
declare @cmd_key int 
set @cmd_id = '{cmd_id}'
set @cmd_tree_key='{cmd_tree_key}'
SET @cmd_power_id='{cmd_power_id}'
set @cmd_name = '{cmd_name}'
set @classify ='{classify}' 
set @remarks = '{remarks}'

--校验信息
if isnull(@cmd_id,'')=''
begin 
	RAISERROR ('SQL:cmd_id不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@cmd_name,'')=''
begin 
	RAISERROR ('SQL:cmd名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@classify,'')=''
begin 
	RAISERROR ('SQL:权限分类不允许为空', 16 ,1 ) ; 
	return 
end 

IF EXISTS(SELECT * FROM y_cmd WHERE cmd_id=@cmd_id)
begin
	RAISERROR ('SQL:cmd_id已经存在', 16 ,1 ) ; 
	return 
end  

IF ISNULL(@cmd_power_id,'')<>'' AND NOT EXISTS(SELECT 1 FROM dbo.y_power WHERE power_id=@cmd_power_id AND classify='10001')
BEGIN
	RAISERROR ('SQL:权限不存在', 16 ,1 ) ; 
	return 
END  
INSERT INTO [dbo].[y_cmd]([cmd_id],[cmd_name],[classify],[remarks],[create_time],[update_time],[cmd_tree_key],[cmd_power_id])
VALUES( @cmd_id  ,@cmd_name  , @classify , @remarks , getdate(), getdate() ,@cmd_tree_key,@cmd_power_id)
SET @cmd_key=@@IDENTITY
 